package eic.muckup.garden;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class WateringActivity extends Activity {
	
	private final String watering = "Watering";
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.water_control_main_view);
		
		SharedPreferences setting = getSharedPreferences(watering, Activity.MODE_PRIVATE);
		ImageView startStopImage = (ImageView) findViewById(R.id.btn_start_stop_watering);
		TextView startStopText = (TextView) findViewById(R.id.start_stop_tbn_text);
		
		setting.edit().putBoolean("isWatering", false);
		
		if(setting.getBoolean("isWatering", false))
		{
			startStopImage.setImageResource(R.drawable.stop);
			startStopText.setText("Stop");
		}
		else
		{
			startStopImage.setImageResource(R.drawable.start);
			startStopText.setText("Start");
		}
		
	}
	
	public void StartStopBtn(View view)
	{
		SharedPreferences setting = getSharedPreferences(watering, MODE_PRIVATE);
		SharedPreferences.Editor settingEditor = setting.edit();
		ImageView startStopImage = (ImageView) findViewById(R.id.btn_start_stop_watering);
		TextView startStopText = (TextView) findViewById(R.id.start_stop_tbn_text);
		
		Context context = getApplication();
		int duration = Toast.LENGTH_SHORT;
		if(setting.getBoolean("isWatering", false))
		{
			settingEditor.putBoolean("isWatering", false);
			settingEditor.commit();
			startStopImage.setImageResource(R.drawable.stop);
			startStopText.setText("Stop");
			
			CharSequence textStart = "You have start Watering";
			Toast toaststart = Toast.makeText(context, textStart, duration);
			toaststart.show();
			
		}
		else
		{
			settingEditor.putBoolean("isWatering", true);
			settingEditor.commit();
			startStopImage.setImageResource(R.drawable.start);
			startStopText.setText("Start");
			
			CharSequence textStop = "You have stop Watering";
			Toast toastend = Toast.makeText(context, textStop, duration);
			toastend.show();
		}
		
		
		
	}
	public void waterCalendar(View view){
		Intent intent = new Intent();
		intent.setClass(this, WateringPlanerActivity.class);
		startActivity(intent);
	}
	
	public void ShowWaterHistory(View view){
		Intent intent = new Intent(this, WateringHistoryActivity.class);
		startActivity(intent);
	}
}
